package com.wuyan.web.auth.api;

import com.wuyan.web.auth.helper.AuthHelper;
import com.wuyan.web.base.aop.ApiLogAnnotation;
import com.wuyan.web.base.helper.auth.LoginInfo;

import com.wuyan.web.base.helper.rep.RepBody;
import com.wuyan.web.base.helper.rep.RepHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 鉴权接口
 */

@Slf4j
@RestController
@RequestMapping("/api")
public class CheckAuthApi implements RepHelper {

    @Autowired
    private AuthHelper authHelper;

    /**
     * 获取当前登录信息，并且校验登录状态
     *
     * @param token 临时授权码
     * @return RepBody<LoginInfo>
     */
    @GetMapping("/check/{token}")
//    @ApiLogAnnotation(name = "CheckAuth:check")
    public RepBody<LoginInfo> check(@PathVariable(value = "token") String token, HttpSession session) throws IOException {
        return ok(authHelper.get(session, token));
    }
}
